/*
 * libcvs.hh
 *
 *  Created on: 18/11/2013
 *      Author: asc
 */

#ifndef LIBCVS_HH_
#define LIBCVS_HH_

// Only include FlexLexer.h if it hasn't been already included

#ifndef yyFlexLexer
#define yyFlexLexer LibcvsFlexLexer
#include <FlexLexer.h>
#endif

// Override the interface for yylex since we namespaced it
#undef YY_DECL
#define YY_DECL int Libcvs::LibcvsFlexScanner::yylex()

#include "Libcvs.tab.hh"
#include <iostream>
using namespace std;

namespace Libcvs {

	class LibcvsFlexScanner : public yyFlexLexer {
		public:
			// save the pointer to yylval so we can change it, and invoke scanner
			LibcvsFlexScanner():yyFlexLexer(){}
			LibcvsFlexScanner(istream* arg_yyin, ostream* arg_yyout):yyFlexLexer(arg_yyin,arg_yyout){}
			int yylex(LibcvsBisonParser::semantic_type * lval) { yylval = lval; return yylex(); }

		private:
			// Scanning function created by Flex; make this private to force usage
			// of the overloaded method so we can get a pointer to Bison's yylval
			int yylex();

			// point to yylval (provided by Bison in overloaded yylex)
			LibcvsBisonParser::semantic_type * yylval;
	};

	class LibcvsParser {
		public:
			LibcvsParser() : parser(scanner) {}
			LibcvsParser(istream* arg_yyin, ostream* arg_yyout) : scanner(arg_yyin,arg_yyout) , parser(scanner) {}

			int parse() {
				return parser.parse();
			}

		private:
			LibcvsFlexScanner scanner;
			LibcvsBisonParser parser;
	};

}  // namespace libcvs

#endif /* LIBCVS_HH_ */
